package home;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.*;

public class datos {

	String a;
	public ResultSet rs;
	float valor = 0;
	CallableStatement cs = null;
	Connection con;

	public void conectar() {

		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			String connectionUrl = "jdbc:sqlserver://localhost\\sqlexpress;"
					+ "database=BD;" + "user=java;" + "password=java";
			con = DriverManager.getConnection(connectionUrl);
			System.out.println("Connected.");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
		}
	}

	public void getarticulo(String articulo) {

		try {
			// Establish the connection.
			conectar();

			cs = con.prepareCall("{call PROC_STOCK(?,?)}");
			cs.registerOutParameter(2, Types.FLOAT);
			cs.setInt(1, Integer.parseInt(articulo));
			cs.execute();
			valor = cs.getFloat(2);

			/*
			 * String SQL = "EXEC PROC_STOCK "+articulo+",0"; Statement stmt =
			 * con.createStatement(); rs = stmt.executeQuery(SQL);
			 */

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void getclientes() throws SQLException{
	conectar();
	
	 try {
		String SQL = "SELECT TOP 5 DESCRIPCION FROM ARTICULOS"; 
		 Statement stmt = con.createStatement(); 
		 rs = stmt.executeQuery(SQL);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
	
	
	
}

}
